var express = require('express')
var fs = require('fs')
var router = express.Router()


router.get('/', (req, res) => {
  let doc={me:'cat'}
  res.json(doc)
})

router.get('/file', [(req, res, next) => {
  fs.readFile("./maybe-valid-file", "utf8", function (err, data) {
    res.locals.data = data;
    next(err);
  });
}, (req, res) => {
  res.locals.data = res.locals.data.split(",")[1]
  res.send(res.locals.data);
}])
router.get('/about', (req, res,next) => {
  Promise.resolve().then(function () {
    throw new Error("BROKEN");
  }).catch(next); // Errors will be passed to Express.
})

module.exports = router